package myDesiign.com.song.factory;

import ch.qos.logback.core.joran.action.NewRuleAction;
import myDesiign.com.song.service.IMyService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author Klys
 * @Date 2023/6/19 12:01
 * @Description
 * @Version 1.0
 */
@Component
public class MyFactory {

    @Resource
    List<IMyService> iMyServices;

    public IMyService getMyService(Integer value) {
        if (value == null) {
            return null;
        }
        return iMyServices.stream()
                .filter(obj -> obj.judge(value))
                .findFirst().orElseThrow(() -> new RuntimeException("无匹配策略"));
    }

    @Override
    public String toString() {
        return "MyFactory{" +
                "iMyServices=" + iMyServices +
                '}';
    }
}
